// mockData.js - 提供宠物和车辆管理的Mock数据服务
// 注意：这是临时解决方案，后续应替换为真实API调用

// 宠物模拟数据
const petsMockData = [
  {
    id: 1,
    name: '球球',
    type: '狗',
    breed: '金毛',
    age: 3,
    color: '金黄色',
    gender: '公',
    vaccineStatus: '已接种',
    owner: { id: 1, name: '张三' },
    registrationNumber: 'PET20230001',
    createdAt: '2023-06-15T08:30:00',
    updatedAt: '2023-08-20T14:20:00'
  },
  {
    id: 2,
    name: '咪咪',
    type: '猫',
    breed: '英国短毛猫',
    age: 2,
    color: '灰白色',
    gender: '母',
    vaccineStatus: '已接种',
    owner: { id: 2, name: '李四' },
    registrationNumber: 'PET20230002',
    createdAt: '2023-07-10T10:15:00',
    updatedAt: '2023-09-05T16:40:00'
  },
  {
    id: 3,
    name: '兔兔',
    type: '兔子',
    breed: '荷兰垂耳兔',
    age: 1,
    color: '白色',
    gender: '母',
    vaccineStatus: '未接种',
    owner: { id: 3, name: '王五' },
    registrationNumber: 'PET20230003',
    createdAt: '2023-08-05T14:20:00',
    updatedAt: '2023-08-05T14:20:00'
  },
  {
    id: 4,
    name: '旺财',
    type: '狗',
    breed: '边牧',
    age: 4,
    color: '黑白色',
    gender: '公',
    vaccineStatus: '已接种',
    owner: { id: 4, name: '赵六' },
    registrationNumber: 'PET20230004',
    createdAt: '2023-05-20T09:45:00',
    updatedAt: '2023-09-10T11:30:00'
  },
  {
    id: 5,
    name: '小白',
    type: '兔子',
    breed: '侏儒兔',
    age: 1,
    color: '白色',
    gender: '公',
    vaccineStatus: '待接种',
    owner: { id: 5, name: '钱七' },
    registrationNumber: 'PET20230005',
    createdAt: '2023-09-01T16:10:00',
    updatedAt: '2023-09-01T16:10:00'
  },
  {
    id: 6,
    name: '花花',
    type: '猫',
    breed: '美国短毛猫',
    age: 3,
    color: '三花',
    gender: '母',
    vaccineStatus: '已接种',
    owner: { id: 6, name: '孙八' },
    registrationNumber: 'PET20230006',
    createdAt: '2023-04-10T13:25:00',
    updatedAt: '2023-08-15T10:50:00'
  },
  {
    id: 7,
    name: '黑豆',
    type: '狗',
    breed: '泰迪',
    age: 2,
    color: '棕色',
    gender: '公',
    vaccineStatus: '已接种',
    owner: { id: 7, name: '周九' },
    registrationNumber: 'PET20230007',
    createdAt: '2023-07-25T11:40:00',
    updatedAt: '2023-09-20T15:15:00'
  },
  {
    id: 8,
    name: '小灰',
    type: '猫',
    breed: '苏格兰折耳猫',
    age: 1,
    color: '灰色',
    gender: '公',
    vaccineStatus: '待接种',
    owner: { id: 8, name: '吴十' },
    registrationNumber: 'PET20230008',
    createdAt: '2023-08-30T17:20:00',
    updatedAt: '2023-08-30T17:20:00'
  },
  {
    id: 9,
    name: '大黄',
    type: '狗',
    breed: '柴犬',
    age: 5,
    color: '黄色',
    gender: '公',
    vaccineStatus: '已接种',
    owner: { id: 9, name: '郑十一' },
    registrationNumber: 'PET20230009',
    createdAt: '2023-03-15T08:50:00',
    updatedAt: '2023-09-12T14:30:00'
  },
  {
    id: 10,
    name: '雪球',
    type: '兔子',
    breed: '安哥拉兔',
    age: 2,
    color: '白色',
    gender: '母',
    vaccineStatus: '未接种',
    owner: { id: 10, name: '王十二' },
    registrationNumber: 'PET20230010',
    createdAt: '2023-06-05T10:30:00',
    updatedAt: '2023-06-05T10:30:00'
  }
];

// 车辆模拟数据
const vehiclesMockData = [
  {
    id: 1,
    licensePlate: '京A12345',
    brand: '奥迪',
    model: 'A6L',
    color: '黑色',
    type: '小型车',
    owner: { id: 1, name: '张三' },
    parkingLocation: 'A区-123号',
    parkingPermitNumber: 'PKG20230001',
    status: '正常',
    createdAt: '2023-05-10T09:00:00',
    updatedAt: '2023-08-15T14:30:00'
  },
  {
    id: 2,
    licensePlate: '京B67890',
    brand: '宝马',
    model: '5系',
    color: '白色',
    type: '小型车',
    owner: { id: 2, name: '李四' },
    parkingLocation: 'B区-045号',
    parkingPermitNumber: 'PKG20230002',
    status: '正常',
    createdAt: '2023-06-20T13:15:00',
    updatedAt: '2023-06-20T13:15:00'
  },
  {
    id: 3,
    licensePlate: '京C54321',
    brand: '丰田',
    model: '汉兰达',
    color: '银色',
    type: 'SUV',
    owner: { id: 3, name: '王五' },
    parkingLocation: 'C区-078号',
    parkingPermitNumber: 'PKG20230003',
    status: '正常',
    createdAt: '2023-04-05T11:40:00',
    updatedAt: '2023-09-01T16:20:00'
  },
  {
    id: 4,
    licensePlate: '京D98765',
    brand: '本田',
    model: '雅阁',
    color: '深蓝色',
    type: '中型车',
    owner: { id: 4, name: '赵六' },
    parkingLocation: 'A区-056号',
    parkingPermitNumber: 'PKG20230004',
    status: '临时',
    createdAt: '2023-07-15T10:30:00',
    updatedAt: '2023-07-15T10:30:00'
  },
  {
    id: 5,
    licensePlate: '京E24680',
    brand: '大众',
    model: '途观L',
    color: '红色',
    type: 'SUV',
    owner: { id: 5, name: '钱七' },
    parkingLocation: 'B区-102号',
    parkingPermitNumber: 'PKG20230005',
    status: '正常',
    createdAt: '2023-03-25T14:50:00',
    updatedAt: '2023-08-20T09:10:00'
  },
  {
    id: 6,
    licensePlate: '京F13579',
    brand: '奔驰',
    model: 'GLC',
    color: '黑色',
    type: 'SUV',
    owner: { id: 6, name: '孙八' },
    parkingLocation: 'C区-033号',
    parkingPermitNumber: 'PKG20230006',
    status: '过期',
    createdAt: '2023-05-30T08:20:00',
    updatedAt: '2023-09-10T15:45:00'
  },
  {
    id: 7,
    licensePlate: '京G86420',
    brand: '日产',
    model: '轩逸',
    color: '灰色',
    type: '小型车',
    owner: { id: 7, name: '周九' },
    parkingLocation: 'A区-089号',
    parkingPermitNumber: 'PKG20230007',
    status: '正常',
    createdAt: '2023-06-10T16:40:00',
    updatedAt: '2023-06-10T16:40:00'
  },
  {
    id: 8,
    licensePlate: '京H97531',
    brand: '别克',
    model: 'GL8',
    color: '银色',
    type: '面包车',
    owner: { id: 8, name: '吴十' },
    parkingLocation: 'B区-067号',
    parkingPermitNumber: 'PKG20230008',
    status: '正常',
    createdAt: '2023-04-15T09:55:00',
    updatedAt: '2023-09-05T11:20:00'
  },
  {
    id: 9,
    licensePlate: '京J36925',
    brand: '福特',
    model: '锐际',
    color: '蓝色',
    type: 'SUV',
    owner: { id: 9, name: '郑十一' },
    parkingLocation: 'C区-041号',
    parkingPermitNumber: 'PKG20230009',
    status: '临时',
    createdAt: '2023-08-05T13:10:00',
    updatedAt: '2023-08-05T13:10:00'
  },
  {
    id: 10,
    licensePlate: '京K85214',
    brand: '特斯拉',
    model: 'Model Y',
    color: '白色',
    type: 'SUV',
    owner: { id: 10, name: '王十二' },
    parkingLocation: 'A区-022号',
    parkingPermitNumber: 'PKG20230010',
    status: '正常',
    createdAt: '2023-07-20T15:25:00',
    updatedAt: '2023-09-15T10:35:00'
  }
];

// 工具函数：分页
const paginate = (array, page, size) => {
  const startIndex = page * size;
  const endIndex = startIndex + size;
  return array.slice(startIndex, endIndex);
};

// 工具函数：过滤
const filterPets = (pets, filters) => {
  return pets.filter(pet => {
    // 按名称过滤
    if (filters.name && !pet.name.toLowerCase().includes(filters.name.toLowerCase())) {
      return false;
    }
    
    // 按类型过滤
    if (filters.type && pet.type !== filters.type) {
      return false;
    }
    
    // 按疫苗状态过滤
    if (filters.vaccineStatus && pet.vaccineStatus !== filters.vaccineStatus) {
      return false;
    }
    
    return true;
  });
};

const filterVehicles = (vehicles, filters) => {
  return vehicles.filter(vehicle => {
    // 按车牌号过滤
    if (filters.licensePlate && !vehicle.licensePlate.toLowerCase().includes(filters.licensePlate.toLowerCase())) {
      return false;
    }
    
    // 按品牌过滤
    if (filters.brand && !vehicle.brand.toLowerCase().includes(filters.brand.toLowerCase())) {
      return false;
    }
    
    // 按车辆类型过滤
    if (filters.type && vehicle.type !== filters.type) {
      return false;
    }
    
    // 按状态过滤
    if (filters.status && vehicle.status !== filters.status) {
      return false;
    }
    
    return true;
  });
};

// 宠物API模拟
export const getPets = (params) => {
  return new Promise((resolve) => {
    // 模拟网络延迟
    setTimeout(() => {
      // 提取分页参数
      const page = params?.page || 0;
      const size = params?.size || 10;
      
      // 过滤数据
      let filteredData = [...petsMockData];
      if (params) {
        filteredData = filterPets(filteredData, params);
      }
      
      // 获取总数
      const totalElements = filteredData.length;
      
      // 进行分页
      const paginatedData = paginate(filteredData, page, size);
      
      // 返回模拟的分页响应
      resolve({
        data: {
          content: paginatedData,
          totalElements: totalElements,
          totalPages: Math.ceil(totalElements / size),
          number: page,
          size: size
        }
      });
    }, 500); // 模拟500ms网络延迟
  });
};

// 车辆API模拟
export const getVehicles = (params) => {
  return new Promise((resolve) => {
    // 模拟网络延迟
    setTimeout(() => {
      // 提取分页参数
      const page = params?.page || 0;
      const size = params?.size || 10;
      
      // 过滤数据
      let filteredData = [...vehiclesMockData];
      if (params) {
        filteredData = filterVehicles(filteredData, params);
      }
      
      // 获取总数
      const totalElements = filteredData.length;
      
      // 进行分页
      const paginatedData = paginate(filteredData, page, size);
      
      // 返回模拟的分页响应
      resolve({
        data: {
          content: paginatedData,
          totalElements: totalElements,
          totalPages: Math.ceil(totalElements / size),
          number: page,
          size: size
        }
      });
    }, 500); // 模拟500ms网络延迟
  });
};

// 宠物删除API模拟
export const deletePet = (id) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log(`Mock删除宠物ID: ${id}`);
      resolve({ data: { message: '删除成功' } });
    }, 300);
  });
};

// 车辆删除API模拟
export const deleteVehicle = (id) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log(`Mock删除车辆ID: ${id}`);
      resolve({ data: { message: '删除成功' } });
    }, 300);
  });
};

// 批量删除API模拟
export const batchDeletePets = (ids) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log(`Mock批量删除宠物IDs: ${ids.join(', ')}`);
      resolve({ data: { message: '批量删除成功' } });
    }, 300);
  });
};

// 批量删除API模拟
export const batchDeleteVehicles = (ids) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log(`Mock批量删除车辆IDs: ${ids.join(', ')}`);
      resolve({ data: { message: '批量删除成功' } });
    }, 300);
  });
}; 